<?php
class App {

	static private $mInstance = null;

	static private $eventType = null;
	
	static private $mess = null;

	static public function & Instance() {
		if (null == self :: $mInstance) {
			$class = __CLASS__;
			self :: $mInstance = new $class;
		}
		return self :: $mInstance;
	}

	function __construct() {
		self :: $eventType = $_POST[Event];
	}

	static public function run() {
		self :: Instance();
		$event_Type = self :: $eventType;
		
		
		if($_POST[Sender]!="261589289" && $_POST[Event] == "ReceiveClusterIM" && self ::checkService()!=1) {
			//$api = new  Api("ExitCluster");
			//$api->doApi($_POST[ClusterNum], "");
			//@ DB :: Query("update td_cluster_favorable set  `is_in_cluster`=0  where ClusterNum='{$_POST[ClusterNum]}'");
			return ;
		}
		if(!isset($_SESSION['isAdd_info'])) {
			//Favorable::addUserInfo();
			$_SESSION['isAdd_info'] = true;
		}
		$controllerfile = ROOT_PATH."Lib/Event/{$event_Type}.class.php";
		myEcho("本次加载事件：".$controllerfile."\n");
		if (file_exists($controllerfile)) {
			//按事件加载处理类
			require_once ("{$controllerfile}");
			$event = new $event_Type;
			$event->run();
			$message = messageReplace($event->message);
			self :: $mess = $message ;
			//最终消息
			if($_GET[flag]==1) {
				return ;
			}
			//echo $message;
		}else{
			if($event_Type=="ReceiveSignatureChanged")
				return;
			$api = new Api("SendMessage");
			$ms = json_encode($_POST);
			$api->doApi("261589289",$controllerfile."\n".$ms);
		}
	}
	
	static public function checkService() {
		$commdMess = DB :: GetTableRow("td_cluster_favorable", array (
				"ClusterNum" => $_POST[ClusterNum]
			));
		
		return $commdMess[is_service];
	}
	
	static public function getMess() {
		return self :: $mess ;
	}
}
?>